home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15733 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: nef.ens.fr!bireme!espel
  2. From: espel@bireme.ens.fr (Roger Espel Llima)
  3. Newsgroups: comp.os.linux.development.apps,comp.unix.programmer,comp.lang.c
  4. Subject: Re: Assembler Statement in C program
  5. Date: 21 Apr 1996 14:00:55 GMT
  6. Organization: Ecole Normale Superieure, Paris
  7. Message-ID: <4ldf2n$gf6@nef.ens.fr>
  8. References: <317A2105.77EF485@bis.co.il>
  9. NNTP-Posting-Host: bireme.ens.fr
  10.  
  11. In article <317A2105.77EF485@bis.co.il>, Meir Dukhan  <meir@bis.co.il> wrote:
  12. >Hi, 
  13. >
  14. >I'm trying to port some piece of C code to linux/unix.
  15. >This code contains statement in assembler.
  16. >
  17. >1. How can I compile it under linux with gcc or gas ?
  18. >
  19. >2. Will this be portable ?
  20.  
  21. [ code snipped ]
  22.  
  23. There are various problems with that; one is that your code is 8086 
  24. assembler, which runs unmodified on 386+ processors only when they are 
  25. in "real mode".  However, Linux runs in protected mode, which is much 
  26. more powerful but not compatible.  Also, your code accesses some 
  27. absolute memory addresses and calls BIOS interrupts, which Linux won't 
  28. let you do (because of memory protection and security, as well as 
  29. different addressing).  Thirdly, none of this would be portable to any 
  30. other Unix system.
  31.  
  32. Porting programs from DOS to Unix isn't that easy if they interact 
  33. directly with the system and/or do any kind of full-screen handling;
  34. to do this properly in Unix (and Linux), you can do either of these:
  35.  
  36.  . use the 'ncurses' library, which is a portable and powerful package 
  37.  of full-screen handling routines.  Check out the manual page for it,
  38.  with "man ncurses".
  39.  
  40.  . use the termcap interface, which is portable but much less of a 
  41.  powerful library.  it might actually be easier to you if you're used
  42.  to low-level handling in DOS, as this is pretty low-level too.
  43.  Check out the man pages for 'termcap'.  Under some Linux versions this 
  44.  is in fact emulated by the ncurses library, and documented in the
  45.  man page for 'curs_termcap'.  Also, this won't handle the tty mode
  46.  (keyboard input mode) for you, so check out the manpage for 
  47.  'tcgetattr' and 'tcsetattr'.
  48.  
  49.  . if you're only going to be using your program on the Linux console
  50.  and other ANSI-compatible terminals, directly use the ANSI escape 
  51.  sequences to do things like clear the screen.  As far as I know they're 
  52.  not on any man page on Linux.  You'll also need to deal with 
  53.  tcgetattr() and tcsetattr() yourself.  It's not portable to general
  54.  terminals.
  55.  
  56. Mail me if you want some sample code that uses the 2nd alternative.
  57.  
  58.     -Roger
  59. --
  60. #!/usr/local/bin/perl                       # e-mail: roger.espel.llima@ens.fr
  61. s**QJwEw=QGv:vt=PGwEvvvEwt=OGUtMGUt=N\@:tKG:A=O> G:GNb,&+ 1%" Z)2" j&zz,+ Y+1*
  62. ,s^$^&E["+0,/0%&- [y*-y&\$+!=Pt:S=QtUSQM%11-RGG444F"##F,/\$Gz)2"/&zz,+F%1*)=^,
  63. s@$@Q SF=QSUUt=PSF:t=OSJ>=NSL>PN/,\$"/F"0-")F))&*yX"+0F#/=NtUUGNtUUG=OtGPtG=@,
  64. y,= :-|"-9,\n "-|, ,s,&,\\"\\,g,s,;,/"/,g,s,",===,g,s,(\d),' 'x$1,eg,print $_;
  65.